function love.load()
    love.window.setMode(1280,720)
    Galaxian=love.graphics.newImage("Invader.png")
    Halfw=370--图片宽度的一半
    Halfh=271
    R=1--图片颜色与透明度
    G=1
    B=1
    A=1
    Orimx=0--发生拖动时，鼠标的原始位置
    Orimy=0
    Oripx=0--发生拖动时，图片的原始位置
    Oripy=0
    X=600--图片绘制位置
    Y=400
    S=1--图片缩放
    Time=0
end

function love.draw()
    love.graphics.setBackgroundColor(0.6,0.6,0.6)
    love.graphics.setColor(R,G,B,A)
    love.graphics.setLineWidth(5)
    if love.mouse.isDown(1) and (love.keyboard.isDown('lctrl') or love.keyboard.isDown('rctrl')) then
        X=Oripx+(love.mouse.getX()-Orimx)
        Y=Oripy+(love.mouse.getY()-Orimy)
    end
    love.graphics.rectangle("line",X-Halfw*S-10,Y-Halfh*S-10,(Halfw*2-1)*S+20,Halfh*2*S+20)--外部线框矩形
    love.graphics.rectangle("fill",X-Halfw*S,Y-Halfh*S,(Halfw*2-1)*S,Halfh*2*S)--图片背景矩形
    love.graphics.draw(Galaxian,X-Halfw*S,Y-Halfh*S,0,S,S)
end

function love.update(dt)
    Time=Time+dt
    if Time>0.1 then
        Time=0
        R=math.random()--每0.1秒变为随机颜色
        G=math.random()
        B=math.random()
    end
end

function love.mousepressed(x, y, button, istouch)
    if button==1 then
        Orimx=love.mouse.getX()--按下代表拖动开始，此时获取鼠标位置
        Orimy=love.mouse.getY()
        Oripx=X
        Oripy=Y
    end
end

function love.wheelmoved(x, y)
    if y>0 and (love.keyboard.isDown('lctrl') or love.keyboard.isDown('rctrl')) then
        S=S+0.1
    elseif y<0 and (love.keyboard.isDown('lctrl') or love.keyboard.isDown('rctrl')) then
        S=S-0.1
    end
    if S<=0 then--让缩放大于零
        S=0.1
    end
end

function love.keypressed(key, scancode, isrepeat)
    if key == "return" then--回车是return
        if A==1 then
            A=0.2
        else
            A=1
        end
    end
end